package com.hspedu.homework;

/**
 * 1.定义一个Person类{name, age,job},初始化Person对象数组，有三个person对象，
 * 并按照age从大到小进行排序，提示：使用冒泡排序
 */
public class Homework01 {
    public static void main(String[] args) {
        Person[] persons = new Person[4];
        persons[0]=new Person("张三",30,"IT");
        persons[1]=new Person("李四",25,"教师");
        persons[2]=new Person("王五",20,"维修厮");
        persons[3]=new Person("王五",22,"维修厮");


        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i]);
        }

        Person personTemp = new Person();
        for (int i = 0; i < persons.length-1; i++) {
            for (int j = 0; j < persons.length-i-1; j++) {
                if (persons[j].getAge()>persons[j+1].getAge()){
                    personTemp = persons[j];
                    persons[j] = persons[j+1];
                    persons[j+1] = personTemp;
                }
            }
        }
        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i]);
        }
    }
}

class Person{
    private String name;
    private int age;
    private String job;

    public Person() {
    }

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}